# Contributor: Raed Rizqie <raed.rizqie@gmail.com>

_realname=jupyter_server
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=2.7.2
pkgrel=1
pkgdesc='Provides backend for core services, APIs and REST endpoints to Jupyter web application (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url='https://jupyter.org/'
license=('spdx:BSD-3-Clause')
options=('!strip')
depends=(
    ${MINGW_PACKAGE_PREFIX}-python
    ${MINGW_PACKAGE_PREFIX}-python-anyio
    ${MINGW_PACKAGE_PREFIX}-python-argon2_cffi
    ${MINGW_PACKAGE_PREFIX}-python-jinja
    ${MINGW_PACKAGE_PREFIX}-python-jupyter_client
    ${MINGW_PACKAGE_PREFIX}-python-jupyter_core
    ${MINGW_PACKAGE_PREFIX}-python-jupyter-server-terminals
    ${MINGW_PACKAGE_PREFIX}-python-jupyter-nbconvert
    ${MINGW_PACKAGE_PREFIX}-python-jupyter-nbformat
    ${MINGW_PACKAGE_PREFIX}-python-packaging
    ${MINGW_PACKAGE_PREFIX}-python-prometheus-client
    ${MINGW_PACKAGE_PREFIX}-python-pywinpty
    ${MINGW_PACKAGE_PREFIX}-python-pyzmq
    ${MINGW_PACKAGE_PREFIX}-python-send2trash
    ${MINGW_PACKAGE_PREFIX}-python-terminado
    ${MINGW_PACKAGE_PREFIX}-python-tornado
    ${MINGW_PACKAGE_PREFIX}-python-overrides
    ${MINGW_PACKAGE_PREFIX}-python-traitlets
    ${MINGW_PACKAGE_PREFIX}-python-websocket-client
    ${MINGW_PACKAGE_PREFIX}-python-jupyter-events)
makedepends=(
    ${MINGW_PACKAGE_PREFIX}-python-build
    ${MINGW_PACKAGE_PREFIX}-python-installer
    ${MINGW_PACKAGE_PREFIX}-python-hatchling
    ${MINGW_PACKAGE_PREFIX}-python-hatch-jupyter-builder)
source=("https://pypi.org/packages/source/${_realname::1}/${_realname/_/-}/${_realname}-${pkgver}.tar.gz")
sha256sums=('d64fb4e593907290e5df916e3c9399c15ab2cd7bdb71cbcd1d36452dbfb30523')

prepare() {
  rm -rf python-build-${MSYSTEM} | true
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"
}

build() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 "LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
